export default {
    data() {
        return {
            goods_id: 0,
            active: 0, // 步骤条
            is_over: false,
            batch_show: false,
            ruleForm: {
                title: '',
                subtitle: '',
                sn: '',
                radio:'1',
                cost_price: '',
                content: '',
                crowd_notice: '', //人群须知
                use_mode: '', //使用方法
                matter_con: '', //注意事项
                cost_contain: '', //费用包含
                cost_exclusive: '', //费用不包含
            },
            rules: {
                title: [{
                    required: true,
                    message: '请输入商品名称',
                    trigger: 'blur'
                }, ],
                subtitle: [{
                    required: true,
                    message: '请输入副标题',
                    trigger: 'blur'
                }, ],
                sn: [{
                    required: true,
                    message: '请输入商品编码',
                    trigger: 'blur'
                }, ],
                cost_price: [{
                    required: true,
                    message: '请输入原价',
                    trigger: 'blur'
                }, ],
            },
            imgList: [], //图片列表
            postData: {}, //七牛云postData
            descImageUrl: '', //图片
            desc_img: false, //是否展示删除
            domain: '', //图片域名
            dynamicTags: [], //标签组
            inputVisible: false, //标签获取焦点
            inputValue: '', //单个标签内容
            traffic_switch: true, //交通信息开关
            traffic_id: 0, //交通信息id
            traffic_table_data: [{ //交通信息列表
                id: 1,
                go_date: '',
                place: "",
                flight: "",
                go_city:'',
                return_city:'',
                go_time: "",
                go_place: "",
                return_time: "",
                return_place: "",
                desc: ''
            }, {
                id: 2,
                go_date: '',
                place: "",
                flight: "",
                go_time: "",
                go_place: "",
                return_time: "",
                return_place: "",
                desc: ''
            }],

            //第二页
            traffic_dialogVisible: false, //交通信息弹窗
            traffic_Form: {
                go_date: '',
                flight: '',
                go_time: '', //出发时间
                go_place: '',
                return_time: '', //到时时间
                return_place: '',
                desc: ''
            },
            traffic_rules: {
                go_date: [{
                    required: true,
                    message: '请选择日期',
                    trigger: 'blur'
                }, ],
                desc: [{
                    required: true,
                    message: '请输入行程说明',
                    trigger: 'blur'
                }, ],
                flight: [{
                    required: true,
                    message: '请输入班次',
                    trigger: 'blur'
                }, ],
                go_time: [{
                    required: true,
                    message: '请选择出发时间',
                    trigger: 'blur'
                }, ],
                go_city: [{
                    required: true,
                    message: '请输入出发地',
                    trigger: 'blur'
                }, ],
                return_city: [{
                    required: true,
                    message: '请输入目的地',
                    trigger: 'blur'
                }, ],
                go_place: [{
                    required: true,
                    message: '请输入出发地点',
                    trigger: 'blur'
                }, ],
                return_time: [{
                    required: true,
                    message: '请选择到达时间',
                    trigger: 'blur'
                }, ],
                return_place: [{
                    required: true,
                    message: '请输入到达地点',
                    trigger: 'blur'
                }, ],
            },
            trip_dialogVisible: false, //添加行程弹窗
            trip_list: [], //行程列表
            trip_day: 0, //第几天
            trip_name: '', //行程名称
            trip_label: [{ //添加行程
                label: '',
                label_content: ''
            }],
            trip_index: '', //行程标签索引

            //第三页
            value6: '',
            checked: '',
            radio: '1',
            week: [
                '周日',
                '周一',
                '周二',
                '周三',
                '周四',
                '周五',
                '周六',
            ],
            days: [],
            setOne: false, //单个设置弹窗
            oneData: {
                one_adult_price: '',
                one_adult_stock: '',
                radio_one: "1",
                one_child_price: '',
                one_child_stock: '',
                one_room_price: ''
            },
            dayIndex: '',
            priceList: []
        }
    },

    /**
     * 进入页面加载
     */
    mounted: function () {
        var that = this;
        //在缓存中获取值
        that.user_name = sessionStorage.getItem("user_name");
        that.user_id = sessionStorage.getItem("user_id");
        that.token = sessionStorage.getItem("access-token");
        if ((!that.token) || (!that.user_id) || (!that.user_name)) {
            that.$router.push('/login');
        }

        if (that.$route.query.goods_id) {
            that.goods_id = that.$route.query.goods_id;
            that.detail();
        }

        that.getQiNiuToken();

        that.getNowMonth();
    },

    /**
     * 方法
     */
    methods: {

        /**
         * 获取七牛云token
         */
        getQiNiuToken: function () {
            let that = this;
            //请求登陆接口
            that.$http.post(that.adminApi.api_url + "/Qiniu/getToken", {
                token: that.token,
            }, {
                emulateJSON: true
            }).then(
                function (res) {
                    // 处理成功的结果
                    that.postData = {
                        token: res.body.upToken,
                    }
                    that.domain = res.body.domain;
                },
                function () {
                    // 处理失败的结果
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ '处理异常' }`
                    });
                });
        },


        /**
         * 上传图片
         * @param file
         * @param fileList
         */
        //删除
        descRemove(file, fileList) {
            let that = this;
            that.imgList = fileList;
        },
        descPictureCardPreview(file) {
            this.descImageUrl = file.url;
            this.desc_img = true;
        },
        descError(res) { //显示错误
            console.log(res)
        },
        descAvatarSuccess(res, file) { //上传成功后在图片框显示图片
            let that = this;
            let imageUrl = {
                url: that.domain + res.key,
                uid: file['raw']['uid']
            };
            that.imgList.push(imageUrl);
        },
        //文件超出个数限制时的钩子
        descExceed(files, fileList) {
            this.$message.error('只能上传一张图片');
        },

        /**
         * 显示交通信息弹窗
         */
        showTraffic: function (e) {
            let that = this;
            that.traffic_id = e;
            that.traffic_dialogVisible = true;
            if (e === 1) {
                if (that.traffic_table_data[0].go_date) {
                    that.traffic_Form.go_date = new Date(that.traffic_table_data[0].go_date);
                }
                that.traffic_Form.flight = that.traffic_table_data[0].flight;
                that.traffic_Form.go_time = that.traffic_table_data[0].go_time;
                that.traffic_Form.go_place = that.traffic_table_data[0].go_place;
                that.traffic_Form.return_time = that.traffic_table_data[0].return_time;
                that.traffic_Form.return_place = that.traffic_table_data[0].return_place;
                that.traffic_Form.desc = that.traffic_table_data[0].desc;
            } else {
                if (that.traffic_table_data[1].go_date) {
                    that.traffic_Form.go_date = new Date(that.traffic_table_data[1].go_date);
                }
                that.traffic_Form.flight = that.traffic_table_data[1].flight;
                that.traffic_Form.go_time = that.traffic_table_data[1].go_time;
                that.traffic_Form.go_place = that.traffic_table_data[1].go_place;
                that.traffic_Form.return_time = that.traffic_table_data[1].return_time;
                that.traffic_Form.return_place = that.traffic_table_data[1].return_place;
                that.traffic_Form.desc = that.traffic_table_data[1].desc;
            }

        },

        /**
         * 添加交通信息
         */
        submitTraffic: function (formName) {
            let that = this;
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    if (that.traffic_id === 1) {
                        that.traffic_table_data[0].go_date = that.formatDateTime(that.traffic_Form.go_date);
                        that.traffic_table_data[0].place = that.traffic_Form.go_city + '-' + that.traffic_Form.return_city;
                        that.traffic_table_data[0].flight = that.traffic_Form.flight;
                        that.traffic_table_data[0].go_time = that.traffic_Form.go_time;
                        that.traffic_table_data[0].go_place = that.traffic_Form.go_place;
                        that.traffic_table_data[0].return_time = that.traffic_Form.return_time;
                        that.traffic_table_data[0].return_place = that.traffic_Form.return_place;
                        that.traffic_table_data[0].desc = that.traffic_Form.desc;
                    } else {
                        that.traffic_table_data[1].go_date = that.formatDateTime(that.traffic_Form.go_date);
                        that.traffic_table_data[1].place = that.traffic_Form.go_city + '-' + that.traffic_Form.return_city;
                        that.traffic_table_data[1].flight = that.traffic_Form.flight;
                        that.traffic_table_data[1].go_time = that.traffic_Form.go_time;
                        that.traffic_table_data[1].go_place = that.traffic_Form.go_place;
                        that.traffic_table_data[1].return_time = that.traffic_Form.return_time;
                        that.traffic_table_data[1].return_place = that.traffic_Form.return_place;
                        that.traffic_table_data[1].desc = that.traffic_Form.desc;
                    }
                    that.traffic_Form = {
                        go_date: '',
                        flight: '',
                        go_time: '',                     //出发时间
                        go_place: '',
                        go_city:'',
                        return_city:'',
                        return_time: '',                 //到时时间
                        return_place: '',
                        desc: ''
                    }
                    that.traffic_dialogVisible = false;
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },


        /**
         * 时间转换
         * @param date
         * @returns {string}
         */
        formatDateTime: function (date) {
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            m = m < 10 ? ('0' + m) : m;
            var d = date.getDate();
            d = d < 10 ? ('0' + d) : d;
            var h = date.getHours();
            var minute = date.getMinutes();
            minute = minute < 10 ? ('0' + minute) : minute;
            // return y + '-' + m + '-' + d + ' ' + h + ':' + minute;
            return y + '-' + m + '-' + d;
        },

        /**
         * 第一页
         */
        first: function (formName) {
            let that = this;
            this.$refs[formName].validate((valid) => {
                if (valid) {
                    if (that.goods_id === 0) {
                        that.addFirst();
                    } else {
                        that.editFirst();
                    }
                } else {
                    console.log('error submit!!');
                    return false;
                }
            });
        },


        /**
         * 添加第一页
         */
        addFirst: function () {
            var that = this;
            if (that.imgList.length === 0) {
                that.$message({
                    type: 'error',
                    message: `操作提示: ${ '请上传图片' }`
                });
                return false;
            }

            const loading = this.$loading({
                lock: true,
                text: 'Loading',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
            });

            //请求的数据
            var formData = {};
            formData.token = that.token;
            formData.title = that.ruleForm.title;
            formData.subtitle = that.ruleForm.subtitle;
            formData.sn = that.ruleForm.sn;
            formData.cost_price = that.ruleForm.cost_price;
            const imgs = [];
            for(var i in that.imgList){
                imgs.push(that.imgList[i]['url']);
            }
            formData.picture = imgs;
            formData.labels = that.dynamicTags;
            if (that.traffic_switch === true) {
                formData.is_traffic = 1;
                formData.traffic = that.traffic_table_data;
            } else {
                formData.is_traffic = 2;
            }

            formData.content = that.ruleForm.content;
            formData.crowd_notice = that.ruleForm.crowd_notice;
            formData.use_mode = that.ruleForm.use_mode;
            formData.matter_con = that.ruleForm.matter_con;
            formData.cost_contain = that.ruleForm.cost_contain;
            formData.cost_exclusive = that.ruleForm.cost_exclusive;
            formData.is_passport = that.ruleForm.radio;

            //请求api
            that.$http.post(that.adminApi.api_url + "/Weekend/add", formData, {
                emulateJSON: true
            }).then(
                function (res) {
                    loading.close();
                    that.active++;
                    that.goods_id = res.body;
                },
                function (res) {
                    // 处理失败的结果
                    loading.close();
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ res.body }`
                    });
                });
        },

        /**
         * 修改第一页
         */
        editFirst: function () {
            var that = this;
            if (that.imgList.length === 0) {
                that.$message({
                    type: 'error',
                    message: `操作提示: ${ '请上传图片' }`
                });
                return false;
            }

            const loading = this.$loading({
                lock: true,
                text: 'Loading',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
            });

            //请求的数据
            var formData = {};
            formData.token = that.token;
            formData.seller_id = that.user_id;
            formData.goods_id = that.goods_id;
            formData.title = that.ruleForm.title;
            formData.subtitle = that.ruleForm.subtitle;
            formData.sn = that.ruleForm.sn;
            formData.cost_price = that.ruleForm.cost_price;
            var imgs = [];
            for(var i in that.imgList){
                imgs.push(that.imgList[i]['url']);
            }
            formData.picture = imgs;
            formData.labels = that.dynamicTags;
            if (that.traffic_switch === true) {
                formData.is_traffic = 1;
                formData.traffic = that.traffic_table_data;
            } else {
                formData.is_traffic = 2;
            }

            formData.content = that.ruleForm.content;
            formData.crowd_notice = that.ruleForm.crowd_notice;
            formData.use_mode = that.ruleForm.use_mode;
            formData.matter_con = that.ruleForm.matter_con;
            formData.cost_contain = that.ruleForm.cost_contain;
            formData.cost_exclusive = that.ruleForm.cost_exclusive;
            formData.is_passport = that.ruleForm.radio;

            //请求api
            that.$http.post(that.adminApi.api_url + "/Weekend/buyedit", formData, {
                emulateJSON: true
            }).then(
                function (res) {
                    loading.close();
                    that.active++;
                    that.goods_id = res.body;
                },
                function (res) {
                    // 处理失败的结果
                    loading.close();
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ res.body }`
                    });
                });
        },

        /**
         * 第二页
         */
        seconds: function () {
            var that = this;
            if (that.trip_list.length === 0) {
                that.$message({
                    type: 'error',
                    message: `操作提示: ${ '请添加行程' }`
                });
                return false;
            }

            const loading = this.$loading({
                lock: true,
                text: 'Loading',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
            });

            //请求的数据
            var formData = {};
            formData.token = that.token;
            formData.seller_id = that.user_id;
            formData.goods_id = that.goods_id;
            formData.trip = that.trip_list;

            //请求api
            that.$http.post(that.adminApi.api_url + "/Weekend/trip_add", formData, {
                emulateJSON: true
            }).then(
                function (res) {
                    loading.close();
                    that.active++;
                    that.goods_id = res.body;
                    that.getCalendarPrice();
                },
                function (res) {
                    // 处理失败的结果
                    loading.close();
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ res.body }`
                    });
                });
        },

        /**
         * 第三页
         */
        third_add: function () {
            var that = this;
            if (that.priceList.length === 0) {
                that.$message({
                    type: 'error',
                    message: `操作提示: ${ '请设置价格' }`
                });
                return false;
            }

            const loading = this.$loading({
                lock: true,
                text: 'Loading',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
            });

            //请求的数据
            var formData = {};
            formData.token = that.token;
            formData.seller_id = that.user_id;
            formData.goods_id = that.goods_id;
            formData.priceList = that.priceList;

            //请求api
            that.$http.post(that.adminApi.api_url + "/Weekend/buyprice", formData, {
                emulateJSON: true
            }).then(
                function (res) {
                    loading.close();
                    that.$router.go(-1);
                },
                function (res) {
                    // 处理失败的结果
                    loading.close();
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ res.body }`
                    });
                });
        },

        /**
         * 移除标签
         * @param tag
         */
        handleClose(tag) {
            this.dynamicTags.splice(this.dynamicTags.indexOf(tag), 1);
        },

        /**
         * 展示标签
         */
        showInput() {
            let that = this;
            if (that.dynamicTags.length >= 4) {
                that.inputVisible = false;
            } else {
                that.inputVisible = true;
                that.$nextTick(_ => {
                    that.$refs.saveTagInput.$refs.input.focus();
                });
            }
        },

        /**
         * 添加标签
         */
        handleInputConfirm() {
            let that = this;
            let inputValue = that.inputValue;
            if (inputValue) {
                that.dynamicTags.push(inputValue);
            }
            that.inputVisible = false;
            that.inputValue = '';
        },

        /**
         * 关闭交通信息弹窗
         */
        closeTraffic: function () {
            let that = this;
            that.traffic_dialogVisible = false;
        },

        /**
         * 闪购详情
         */
        detail: function () {
            var that = this;
            //请求的数据
            var formData = {};
            formData.token = that.token;
            formData.goods_id = that.goods_id;
            formData.seller_id = that.user_id;

            //请求邀请者列表
            that.$http.post(that.adminApi.api_url + "/Weekend/buyshow", formData, {
                emulateJSON: true
            }).then(
                function (res) {
                    that.ruleForm.title = res.body.title;
                    that.ruleForm.subtitle = res.body.subtitle;
                    that.ruleForm.sn = res.body.sn;
                    if(res.body.picture){
                        for(var i in res.body.picture){
                            that.imgList.push({
                                url: res.body.picture[i],
                                picture: res.body.picture[i]
                            })
                        }
                    }

                    that.ruleForm.cost_price = res.body.cost_price;

                    //标签
                    that.dynamicTags = res.body.labels;
                    //产品介绍
                    that.ruleForm.content = res.body.content;
                    //交通信息
                    if (res.body.is_traffic === 1) {
                        that.traffic_switch = true;
                        that.traffic_table_data = res.body.traffic;
                    } else {
                        that.traffic_switch = false;
                    }
                    that.ruleForm.crowd_notice = res.body.crowd_notice;
                    that.ruleForm.use_mode = res.body.use_mode;
                    that.ruleForm.matter_con = res.body.matter_con;
                    that.ruleForm.cost_contain = res.body.cost_contain;
                    that.ruleForm.cost_exclusive = res.body.cost_exclusive;
                    that.ruleForm.radio = res.body.is_passport.toString();

                    if (res.body.scheduling.length !== 0) {
                        that.trip_list = res.body.scheduling;
                    }
                },
                function () {
                    // 处理失败的结果
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ '处理异常' }`
                    });
                });
        },

        /**
         * 显示添加行程弹窗
         */
        show_trip: function () {
            let that = this;

            that.trip_dialogVisible = true;
            if (that.trip_list.length <= 0) {
                that.trip_day = 1;
            } else {
                that.trip_day = parseInt(that.trip_list.length) + 1;
            }
        },

        /**
         * 关闭添加行程弹窗
         */
        close_trip: function () {
            let that = this;
            that.trip_dialogVisible = false;
            that.trip_name = '';
            that.trip_label = [{
                label: '',
                label_content: ''
            }];
            that.trip_index = '';
        },

        /**
         * 添加行程标签
         */
        showTripLabel: function () {
            let that = this;
            that.trip_label.push({
                label: '',
                label_content: ''
            })
        },

        /**
         * 删除行程标签
         */
        delTripLabel: function (e) {
            let that = this;
            if (e === 0) {
                that.$message({
                    type: 'error',
                    message: `操作提示: ${ '不能删除第一个标签组' }`
                });
                return false;
            }
            that.trip_label.splice(e, 1);
        },

        /**
         * 添加完成
         */
        over_trip: function () {
            let that = this;
            if (that.trip_name === '') {
                that.$message({
                    type: 'error',
                    message: `操作提示: ${ '行程名称不能为空' }`
                });
                return false;
            }
            if (that.trip_index === '') {
                that.trip_list.push({
                    trip_day: that.trip_day,
                    trip_name: that.trip_name,
                    trip_label: that.trip_label
                });
            } else {
                that.trip_list[that.trip_index].trip_name = that.trip_name;
            }
            that.trip_dialogVisible = false;
            that.trip_name = '';
            that.trip_label = [{
                label: '',
                label_content: ''
            }];
            that.trip_index = '';
        },

        /**
         * 修改行程
         */
        editTrip: function (e) {
            let that = this;
            that.trip_index = e;
            that.trip_dialogVisible = true;
            that.trip_label = that.trip_list[e].trip_label;
            that.trip_day = that.trip_list[e].trip_day;
            that.trip_name = that.trip_list[e].trip_name;
        },

        /**
         * 删除行程
         */
        delTrip: function (e) {
            let that = this;
            that.trip_list.splice(e, 1);
        },


        /**
         * 获取当月日历
         */
        getNowMonth: function () {
            let that = this;
            const date = new Date();
            const cur_year = date.getFullYear();
            const cur_month = date.getMonth() + 1;
            that.getCalendar(cur_year, cur_month);
        },

        /**
         * 上月日历
         */
        lastMonth: function () {
            let that = this;
            if (parseInt(that.cur_month) === 1) {
                that.cur_year = that.cur_year - 1;
                that.getCalendar(that.cur_year, 12);
            } else {
                that.getCalendar(that.cur_year, (parseInt(that.cur_month) - 1));
            }
        },

        /**
         * 下月日历
         */
        nextMonths: function () {
            let that = this;
            if (parseInt(that.cur_month) === 12) {
                that.cur_year = that.cur_year + 1;
                that.getCalendar(that.cur_year, 1);
            } else {
                that.getCalendar(that.cur_year, (parseInt(that.cur_month) + 1));
            }
        },

        /**
         * 获取日历详细信息
         */
        getCalendar: function (cur_year, cur_month) {
            var that = this;
            // var cur_day = date.getDate();
            that.cur_year = cur_year;
            // console.log(cur_month);
            that.cur_month = cur_month > 9 ? cur_month : '0' + parseInt(cur_month);


            //获取日期
            that.calculateDays(cur_year, cur_month);

            //获取日期的星期
            that.getFirstDayOfWeek(cur_year, cur_month);

            //日期前的空格
            that.calculateEmptyGrids(cur_year, cur_month);

            //当月天数
            that.getThisMonthDays(cur_year, cur_month);

            that.nowDay = that.getThisMonthDays(cur_year, cur_month)
        },

        /**
         * 获取当月天数(操作)
         */
        calculateDays(year, month) {
            var that = this;
            var days = [];
            const thisMonthDays = this.getThisMonthDays(year, month);
            month = parseInt(month)
            month = month > 9 ? month : '0' + month;
            for (let i = 1; i <= thisMonthDays; i++) {
                parseInt(i);
                var day = i > 9 ? i : '0' + i;
                var datetime = year + '-' + month + '-' + day;

                //查询今天是时间
                var day2 = new Date();
                day2.setTime(day2.getTime());
                //最近接收日期
                if (day2.getDate() < 10) {
                    var s2 = day2.getFullYear() + "-" + '0' + (day2.getMonth() + 1) + "-" + '0' + day2.getDate();
                } else {
                    var s2 = day2.getFullYear() + "-" + '0' + (day2.getMonth() + 1) + "-" + day2.getDate();
                }

                if (datetime === s2) {
                    var is_today = true;
                } else {
                    var is_today = false;
                }
                let price = that.getPrice(datetime);
                days.push({
                    day: day,
                    date: datetime,
                    is_today: is_today,
                    adult_price: price.adult_price,
                    adult_stock: price.adult_stock,
                    child_price: price.child_price,
                    child_stock: price.child_stock,
                    room_price: price.room_price,
                    radio_one: price.radio_one,
                });
            }
            that.days = days;
        },

        /**
         * 当月的天数
         */
        getThisMonthDays(year, month) {
            return new Date(year, month, 0).getDate();
        },

        /**
         * 获取日期的星期
         */
        getFirstDayOfWeek(year, month) {
            return new Date(Date.UTC(year, month - 1, 1)).getDay();
        },

        /**
         * 当月天数前的空格
         */
        calculateEmptyGrids(year, month) {
            let that = this;
            const firstDayOfWeek = this.getFirstDayOfWeek(year, month);
            let empytGrids = [];
            if (firstDayOfWeek > 0) {
                for (let i = 0; i < firstDayOfWeek; i++) {
                    empytGrids.push(i);
                }
                that.hasEmptyGrid = true;
                that.empytGrids = empytGrids;

            } else {
                that.hasEmptyGrid = false;
                that.empytGrids = []

            }
        },

        /**
         * 单个设置弹窗开启
         */
        setOneOpen: function (e) {
            let that = this;
            const date = new Date();
            const cur_year = date.getFullYear();
            const cur_month = date.getMonth() + 1;
            const day = date.getDate();
            let month = cur_month > 9 ? cur_month : '0' + cur_month
            let today = day > 9 ? day : '0' + day;
            let now = cur_year + '-' + month + '-' + today;

            //小于今天禁止设置
            if (now > that.days[e].date) {
                that.$message({
                    type: 'error',
                    message: `敬告: ${ '不能设置今天之前的信息哦' }`
                });
                return false;
            }
            that.oneData.one_adult_price = that.days[e].adult_price;
            that.oneData.one_adult_stock = that.days[e].adult_stock;
            that.oneData.one_child_price = that.days[e].child_price;
            that.oneData.one_child_stock = that.days[e].child_stock;
            that.oneData.one_room_price = that.days[e].room_price;
            that.oneData.radio_one = that.days[e].radio_one.toString();

            that.setOne = true;
            that.dayIndex = e;
        },

        /**
         * 单个设置完毕
         */
        setOneOver: function () {
            let that = this;
            if (that.dayIndex === '') {
                that.$message({
                    type: 'error',
                    message: `错误提示: ${ '获取日历下标错误' }`
                });
                return false;
            }

            if (!that.oneData.one_adult_price) {
                that.$message({
                    type: 'error',
                    message: `错误提示: ${ '请输入成人价格' }`
                });
                return false;
            }

            if (!that.oneData.one_adult_stock) {
                that.$message({
                    type: 'error',
                    message: `错误提示: ${ '请输入成人库存' }`
                });
                return false;
            }

            if (that.oneData.radio_one === '1') {
                if (!that.oneData.one_child_price) {
                    that.$message({
                        type: 'error',
                        message: `错误提示: ${ '请输入儿童价格' }`
                    });
                    return false;
                }
                if (!that.oneData.one_child_stock) {
                    that.$message({
                        type: 'error',
                        message: `错误提示: ${ '请输入儿童库存' }`
                    });
                    return false;
                }
            }
            if (!that.oneData.one_room_price) {
                that.$message({
                    type: 'error',
                    message: `错误提示: ${ '请输入单房差' }`
                });
                return false;
            }

            //设置价格到price缓存区
            if (that.days[that.dayIndex].adult_price === '') {
                that.priceList.push({
                    adult_price: that.oneData.one_adult_price,
                    adult_stock: that.oneData.one_adult_stock,
                    child_price: that.oneData.one_child_price,
                    child_stock: that.oneData.one_child_stock,
                    room_price: that.oneData.one_room_price,
                    radio_one: that.oneData.radio_one.toString(),
                    date: that.days[that.dayIndex].date,
                    id: 0
                });
            } else {
                for (var i in that.priceList) {
                    if (that.priceList[i].date === that.days[that.dayIndex].date) {
                        that.priceList[i].adult_price = that.oneData.one_adult_price;
                        that.priceList[i].adult_stock = that.oneData.one_adult_stock;
                        that.priceList[i].child_price = that.oneData.one_child_price;
                        that.priceList[i].child_stock = that.oneData.one_child_stock;
                        that.priceList[i].room_price = that.oneData.one_room_price;
                        that.priceList[i].radio_one = that.oneData.radio_one.toString();
                    }
                }
            }

            that.oneData = {
                one_adult_price: '',
                one_adult_stock: '',
                radio_one: "1",
                one_child_price: '',
                one_child_stock: '',
                one_room_price: ''
            };
            that.setOne = false;
            that.dayIndex = '';
            that.getCalendar(that.cur_year, that.cur_month);
        },

        /**
         * 获取设置的值
         */
        getPrice: function (date) {
            let that = this;
            var price = {
                adult_price: '',
                adult_stock: '',
                child_price: '',
                child_stock: '',
                room_price: '',
                radio_one: '1',
            };
            for (let i in that.priceList) {
                if (that.priceList[i].date === date) {
                    price.adult_price = that.priceList[i].adult_price;
                    price.adult_stock = that.priceList[i].adult_stock;
                    price.child_price = that.priceList[i].child_price;
                    price.child_stock = that.priceList[i].child_stock;
                    price.room_price = that.priceList[i].room_price;
                    price.radio_one = that.priceList[i].radio_one.toString();
                }
            }
            return price
        },

        /**
         * 单个设置弹窗关闭
         */
        setOneClose: function () {
            let that = this;
            that.setOne = false;
        },

        /**
         * 获取日历价格
         */
        getCalendarPrice: function () {
            var that = this;
            //请求的数据
            var formData = {};
            formData.token = that.token;
            formData.goods_id = that.goods_id;

            //请求api
            that.$http.post(that.adminApi.api_url + "/Weekend/price_list", formData, {
                emulateJSON: true
            }).then(
                function (res) {
                    if (res.body) {
                        for (var i in res.body) {
                            that.priceList.push({
                                adult_price: res.body[i].adult_price,
                                adult_stock: res.body[i].adult_count,
                                child_price: res.body[i].children_price,
                                child_stock: res.body[i].children_count,
                                room_price: res.body[i].room_price,
                                radio_one: res.body[i].is_children.toString(),
                                date: res.body[i].date,
                                id: res.body[i].id
                            });
                        }
                        that.getCalendar(that.cur_year, that.cur_month);
                    }
                },
                function (res) {
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ res.body }`
                    });
                });
        },

        /**
         * 返回上一页
         */
        back() {
            this.$router.go(-1)
        }
    }
}